<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
 <link href="/res/third/powerFloat/css/powerFloat.css" rel="stylesheet" type="text/css" />
<script src="/res/third/powerFloat/js/mini/jquery-powerFloat-min.js" type="text/javascript"></script>
<style type="text/css">
	.aui_dialog td{
		padding: 10px 5px; 	
	} 
	.aui_dialog td.aui_header{
		padding: 0px;
	}
	
	#set div{
	   height:60px;
	}
	
	.creat div{
	   height:60px;
	}
	
	.change {
	   margin-left:70px;
	}
	 
</style>
<script type="text/javascript">

/* $(document).ready(function(){
	$(".checkfath").click(function(){
		$(".checkedchild").prop("checked",this.checked);
	})
	 
})
 */

 var exceldialog=null;
 function addpicture(){
 	exceldialog = art.dialog.uploadFile("上传礼品",{callback:"uploadcallback",userpath:"admin",extensions:"gif,jpg,png,jepg"});
 }
 
 function uploadcallback(response){
		//alert(response.url);
		//alert(params.id);
		exceldialog.close();
		$("#mainlpdiv").append("<div class='lpdiv'>"
				+"<a target='_blank' class='showimgs' href='"+response.url+"'>"+response.url+"</a>"
				+"<a onclick='delimgs(this)' class='delimgas'>删除</a></div>");
	}

	function delimgs(node){
		$(node).parents(".lpdiv").remove();
	}
 
 $(function() {

	    $("#startdate,#startdate2").datebox({
	        formatter: function (date) {
	            var y = date.getFullYear();
	            var m = date.getMonth() + 1;
	            var d = date.getDate();
	            return y + '-' + m + '-' + d;
	        },
	        onSelect: function (dateselect) {
	            //enddate清空
	            $('#enddate').datebox('setValue', '');
	            $("#enddate").datebox("calendar").calendar({
	                validator: function (date) {
	                    return dateselect <= date;
	                }
	            });
	        }
	    });

	    $("#enddate").datebox({
	        formatter: function (date) {
	            var y = date.getFullYear();
	            var m = date.getMonth() + 1;
	            var d = date.getDate();
	            return y + '-' + m + '-' + d;
	        }
	    })
	    
	})

 

 
/* 
 function newaddprize(){
	 dialog=art.dialog({
		   title:"新增奖品",
		   width:500,
		   lock:true,
		   content:document.getElementById("create")
	       
	   });
} */

//奖品编号:giftCode 奖品排序:type 奖品名称:giftName 奖品价值:giftPrice 中奖概率:probability 过期时间overdueDate
//奖品图片:imgUrl,奖品数量:amount 每日最高中奖数量:perdayAmount
function save(){
	var giftCode=$("#giftCode").val().trim();
	if(giftCode==""){
		alert("奖品编号不能为空");
		return false;
	}
	var seq=$("#seq").val().trim();
	if(seq==""){
		alert("奖品排序不能为空");
		return false;
	}
	var giftName=$("#giftName").val().trim();
	if(giftName==""){
		alert("奖品名称不能为空");
		return false;
	}
	var giftPrice=$("#giftPrice").val().trim();
	var t=/^([1-9]\d*|0)(\.\d{1,2})?$/;
	if(!t.test(giftPrice)){
		alert("请输入正确的礼品价格模式");
		return false;
	}
	var probability=$("#probability").val().trim();
	if(probability==""){
		alert("请输入中奖概率");
		return false;
	}
	var overdueDate=$("[name='overdueDate']").val().trim();
	if(overdueDate==""){
		alert("请输入过期日期");
		return false;
	}
	
	/* var imgUrlCount=$("#imgUrl").value().trim();
	if(imgUrlCount==0){
		alert("至少上传一张图片");
		return false;
	} */
	
	
	var amount=$("#amount").val().trim();
	if(amount==""){
		alert("请输入奖品数量");
		return false;
	}
	var perdayAmount=$("#perdayAmount").val().trim();
	if(perdayAmount==""|| perdayAmount>amount){
		alert("提示:请输入正确的每日最高中奖数量并且不能多于奖品数量");
		return false;
	}
	$.ajax({
		type:"post",
		dataType:"json",
		url:"/prize/inser.do",
		data:$("form").serialize(),
	    beforeSend:function(){
		 art.dialog.tips("加载中");
	  },
	  success:function(da){
		  if(da.success){
			  location.reload();//刷新页面
			  confirm(da.msg);
		  }
	  }
	});
}
//编辑页面
function updat(id){
	top.addTempTab("/prize/updat_list.do?id="+id);
}
//新增页面
function newaddprize(){
	top.addTempTab("/prize/inser.do");
}

function setzhong(id){
	$("#setId").val(id);
	dialog=art.dialog({
		   title:"内定中奖",
		   width:500,
		   lock:true,
		   content:document.getElementById("set")
	       
	   });
}

function deleteById(id,removed){
	var con=confirm("确认删除吗");
	if(con){
		$.ajax({
			type:"post",
			dataType:"json",
			url:"/prize/deleteById.do",
		    data:{id:id,removed:removed},
		    success:function(da){
				  if(da.success){
					  location.reload();//刷新页面
					  confirm(da.msg);
				  }
			  }
		});
	}
	
}


function trueset(){
	/* var appointTel=$("#appointTel").val().trim();
	if(appointTel==""||appointTel.length!=11){
		alert("请输入手机位为11的正确的手机格式");
		return false;
	}
	var appointDate=$("[name='appointDate']").val().trim();
	if(appointDate==""){
		alert("请输入中奖时间");
		return false;
	} */
	$.ajax({
		type:"post",
		dataType:"json",
		url:"/prize/trueset.do",
		data:$("form").serialize(),  
		beforeSend:function(){
			 art.dialog.tips("加载中");
		  },
		  success:function(da){
			  if(da.success){
				  location.reload();//刷新页面
				  confirm(da.msg);
			  }
		  }
	});
}

</script>

</head>
<body>
    <div class="panel panel-info panel-content" style="height: 100%;overflow-y: scroll;">
      <div class="panel-heading" style="position: relative;">
			<form id="soform" method="post">
				<table>
					<tr>
						<td style="padding-left:0px;font-size: 16px;font-family: inherit;color: inherit;">
							<input  type="button" class="btn btn-info"  onclick="newaddprize()" value="新增奖品">
						</td>
					</tr>
				</table>
				</form>		
		</div>
      
      <table class="table table-hover table-bordered table-striped table-condensed">
         <tr>
           <th>奖品编号</th>
           <th>奖品名称</th>
           <th>排序号</th>
           <th>中奖概率</th>
           <th>剩余数量</th>
           <th>已经中奖</th>
           <th>指定中奖</th>
           <th>过期时间</th>
           <th>操作</th>
         </tr>
         [#list pagination.list as set]
         <tr>
            <td align="center">${set.giftCode!}</td>
            <td align="center">${set.giftName!}</td>
            <td align="center">${set.seq!}</td>
            <td align="center">${set.probability!}</td>
            <td align="center">${set.stockAmount!}</td>
            <td align="center">${set.recordCount!}</td>
            <td align="center">${set.appointTel!}</td>
            <td align="center">${set.overdueDate?string("yy-MM-dd")!}</td>
            <td align="center">
            <input type="button" value="编辑" class="btn-info" onclick="updat('${set.id!}')">
            <input type="button" value="设置中奖" class="btn-info" onclick="setzhong('${set.id!}')">
            <input type="button" value="删除" class="btn-info" onclick="deleteById('${set.id!}','${set.removed!}')">
            </td>
         </tr>
         [/#list]
      </table>
         <div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]
         </div>   
      </div>
      
      <!-- <div id="create"  class="creat"  style="width: 700px;">
         <form method="post"  role="form">class="form-horizontal"
			<input type="hidden" name="id"  id="id">
			        <div>
				      <label>奖品编号:</label>
				       <input  type="text" id="giftCode" name="giftCode">
				       <label class="change">奖品类型:</label>
				        <select name="type">
					           <option value="1">实物</option>
					           <option value="2">虚拟</option>
					           <option value="3">积分</option>
					    </select>
				    </div>
				    
				    <div>
				      <label>奖品排序:</label>
				       <input  type="text" id="seq" name="seq">
				       <label class="change">奖品名称:</label>
				       <input  type="text" id="giftName"  name="giftName">
				    </div>
				       
				   <div>
				      <label>奖品价值:</label>
				       <input  type="text" id="giftPrice" name="giftPrice">
				       <label class="change">中奖概率:</label>
				       <input type="text" id="probability" name="probability">
				    </div>
				   
				   
				   <div>
				      <label>过期时间:</label>
				       <input id="startdate"  name="overdueDate">
				       <label class="change">奖品图片:</label>
				       <input class="btn btn-info" id="imgUrl" type="button" onclick="addpicture()" value="礼品图片">
				       <a target="_blank" class="" href="${url!}">${url!}</a>
				    </div>
				    
				    <div>
				      <label>奖品数量:</label>
				       <input  type="text"  name="amount" id="amount">
				       <label class="change">每日最高中奖数量:</label>
				       <input  type="text" id="perdayAmount" name="perdayAmount">
				    </div>
				    
		           <div style="margin-left:270px">
			            <input class="btn btn-info"  type="button" value="保存" onclick="save()">
			       </div>
			 </form>
		</div>	  
			   -->
    
    <div id="set" style="display:none;">
       <form id="signupForm" class="form-horizontal"  method="post" role="form">
				<input type="hidden" name="id" id="setId">
				<div class="form-group">
					<label>中奖手机:</label> <input id="appointTel" name="appointTel">
				</div>
                <div class="form-group">
					<label>中奖时间:</label> 
					<input id="startdate2"  style="height:26px" name="appointDate">
				</div>
				<div class="form-group" style="margin-top: 10px;">
					<div style="text-align: center;">
						<button onclick="trueset();" type="button" class="btn btn-info">确认设置</button>
					</div>
				</div>
		</form>		
    </div>
    
    
</body>
</html>